package com.canaan.business.controller.pc.basic;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.business.domain.basic.StorehousePermission;
import com.canaan.business.service.basic.IStorehousePermissionService;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * 仓库权限Controller
 *
 * @author ruoyi
 * @date 2023-02-01
 */
@Api(tags = "仓库权限")
@RestController
@RequestMapping("/basic/storehousePermission")
public class StorehousePermissionController extends BaseController {
    @Resource
    private IStorehousePermissionService storehousePermissionService;

    /**
     * 查询仓库权限列表
     */
    @ApiOperation(value = "查询仓库权限列表")
    @GetMapping("/list")
    public TableDataInfo list(StorehousePermission storehousePermission) {
        startPage();
        List<StorehousePermission> list = storehousePermissionService.selectStorehousePermissionList(storehousePermission);
        return getDataTable(list);
    }

    /**
     * 导出仓库权限列表
     */
    @ApiOperation(value = "导出仓库权限列表")
    @Log(title = "仓库权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StorehousePermission storehousePermission) {
        List<StorehousePermission> list = storehousePermissionService.selectStorehousePermissionList(storehousePermission);
        ExcelUtil<StorehousePermission> util = new ExcelUtil<StorehousePermission>(StorehousePermission.class);
        util.exportExcel(response, list, "仓库权限数据");
    }

    /**
     * 获取仓库权限详细信息
     */
    @ApiOperation(value = "获取仓库权限详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(storehousePermissionService.selectStorehousePermissionById(id));
    }

    /**
     * 新增仓库权限
     */
    @ApiOperation(value = "新增仓库权限")
    @Log(title = "仓库权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StorehousePermission storehousePermission) {
        return toAjax(storehousePermissionService.insertStorehousePermission(storehousePermission));
    }

    /**
     * 修改仓库权限
     */
    @ApiOperation(value = "修改仓库权限")
    @Log(title = "仓库权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StorehousePermission storehousePermission) {
        return toAjax(storehousePermissionService.updateStorehousePermission(storehousePermission));
    }

    /**
     * 删除仓库权限
     */
    @ApiOperation(value = "删除仓库权限")
    @Log(title = "仓库权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{nos}")
    public AjaxResult remove(@PathVariable String[] nos) {
        return toAjax(storehousePermissionService.deleteStorehousePermissionByIds(nos));
    }


    /**
     * 根据仓库编号，查询仓库权限列表
     */
    @ApiOperation(value = "getPermissionsByStorehouseNo")
    @GetMapping("/getPermissionsByStorehouseNo")
    public AjaxResult getPermissionsByStorehouseNo(String storehouseNo) {
        return success(storehousePermissionService.getPermissionsByStorehouseNo(storehouseNo));
    }
}
